﻿Module Functions
    'Arrays are declared here, but the data is in the Main.vb code. Will clean it later, just testing this out right now.
    Public arrayRcon(3, 15) As String
    Public arrayCvar(7) As String


    'All self-made functions go here.
    'I always start my own functions with func, to keep them seperated from the standard functions.

#Region "Messageboxes"
    'These are messageboxes, they use the standard messagebox.show function, but it makes it easier for me to write them quickly. I'm lazy, remember..
    ''' <summary>
    ''' Simple Messagebox function using "Error!" as title, Error as Icon and OK as buttons.
    ''' Used to abort current action.
    ''' </summary>
    ''' <param name="text">Text to show in the messagebox</param>
    Function funcMsgError(ByVal text As String) As MsgBoxResult
        'An error occured:
        funcMsgError = MessageBox.Show(text, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Function

    ''' <summary>
    ''' Simple Messagebox function using "Warning!" as title, Warning as Icon and OKCancel as buttons
    ''' </summary>
    ''' <param name="text">Text to show in the messagebox</param>
    Function funcMsgWarning(ByVal text As String) As MsgBoxResult
        'You did something which you should - perhaps - not do:
        funcMsgWarning = MessageBox.Show(text, "Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
    End Function

    ''' <summary>
    ''' Simple Messagebox function using "Are you sure?" as title, Questionmark as Icon and OKCancel as buttons
    ''' </summary>
    ''' <param name="text">Text to show in the messagebox</param>
    Function funcMsgQuestion(Optional ByVal text As String = "Are you sure you want to continue? Please make sure everything is correct.") As MsgBoxResult
        'You did something that just needs double checking or something:
        'This one doesn't need the text, if you leave it empty it will use default text.
        funcMsgQuestion = MessageBox.Show(text, "Are you sure?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
    End Function
    'End of the messageboxes :)
#End Region

    ''' <summary>
    ''' Builds the code and saves it as a string.
    ''' </summary>
    Function funcCodeBuild() As String
        'Building the code here.


        'Setting up the values.
        'General
        Dim GeneralServerName As String = "hostname " & """" & frmMain.txtGeneralServerName.Text & """"
        Dim GeneralPassRcon As String = "rcon_password " & """" & frmMain.txtGeneralPassRcon.Text & """"
        Dim GeneralPassServer As String = "sv_password " & """" & frmMain.txtGeneralPassServer.Text & """"
        Dim GeneralContact As String = "sv_contact " & frmMain.txtGeneralContact.Text
        Dim GeneralLan As String = "sv_lan " & frmMain.cbGeneralLan.SelectedIndex
        Dim GeneralRegion As String
        Select Case frmMain.cbGeneralRegion.SelectedIndex
            Case 0, 1, 2, 3, 4, 5, 6, 7
                GeneralRegion = "sv_region " & frmMain.cbGeneralRegion.SelectedIndex & " //" & frmMain.cbGeneralRegion.SelectedItem
            Case 8
                GeneralRegion = "sv_region 255" & "//" & frmMain.cbGeneralRegion.SelectedItem 'World uses a value of 255, don't ask me why.
            Case Else
                GeneralRegion = "sv_region 255 //Bad index chosen within cbGeneralRegion, reverting to default"
        End Select

        'Server Cvars
        Dim CvarFriendlyFire As String = "mp_friendlyfire " & frmMain.cbCvarFriendlyFire.SelectedIndex
        Dim CvarFootsteps As String = "mp_footsteps " & frmMain.cbCvarFootsteps.SelectedIndex
        Dim CvarAutoTeamBal As String = "mp_autoteambalance " & frmMain.cbCvarAutoTeamBal.SelectedIndex
        Dim CvarAutokick As String = "mp_autokick " & frmMain.cbCvarAutokick.SelectedIndex
        Dim CvarFlashlight As String = "mp_flashlight " & frmMain.cbCvarFlashlight.SelectedIndex
        Dim CvarTkPunish As String = "mp_tkpunish " & frmMain.cbCvarTkPunish.SelectedIndex
        Dim CvarForceCam As String = "mp_forcecam " & frmMain.cbCvarForceCam.SelectedIndex
        Dim CvarAllTalk As String = "sv_alltalk " & frmMain.cbCvarAllTalk.SelectedIndex
        Dim CvarPausable As String = "sv_pausable " & frmMain.cbCvarPausable.SelectedIndex
        Dim CvarConsistency As String = "sv_consistency " & frmMain.cbCvarConsistency.SelectedIndex
        Dim CvarCheats As String = "sv_cheats " & frmMain.cbCvarCheats.SelectedIndex
        Dim CvarAllowUpload As String = "sv_allowupload " & frmMain.cbCvarAllowUpload.SelectedIndex
        Dim CvarAllowDownload As String = "sv_allowdownload " & frmMain.cbCvarAllowDownload.SelectedIndex
        Dim CvarMaxSpeed As String = "sv_maxspeed " & frmMain.txtCvarMaxSpeed.Text
        Dim CvarLimitTeams As String = "mp_limitteams " & frmMain.txtCvarLimitTeams.Text
        Dim CvarHostagePenalty As String = "mp_hostagepenalty " & frmMain.txtCvarHostagePenalty.Text
        Dim CvarVoiceEnable As String = "sv_voiceenable " & frmMain.cbCvarVoiceEnable.SelectedIndex
        Dim CvarAllowSpectate As String = "mp_allowspectators " & frmMain.cbCvarAllowSpectate.SelectedIndex
        Dim CvarTimeLimit As String = "mp_timelimit " & frmMain.txtCvarTimeLimit.Text
        Dim CvarChatTime As String = "mp_chattime " & frmMain.txtCvarChatTime.Text
        Dim CvarTimeout As String = "sv_timeout " & arrayCvar(frmMain.cbCvarTimeout.SelectedIndex)

        'Round Cvars
        Dim Cvar2FreezeTime As String = "mp_freezetime " & frmMain.txtCvar2FreezeTime.Text
        Dim Cvar2RoundTime As String = "mp_roundtime " & frmMain.txtCvar2RoundTime.Text
        Dim Cvar2StartMoney As String = "mp_startmoney " & frmMain.txtCvar2StartMoney.Text
        Dim Cvar2BombTimer As String = "mp_c4timer " & frmMain.txtCvar2BombTimer.Text
        Dim Cvar2FragLimit As String = "mp_fraglimit " & frmMain.txtCvar2FragLimit.Text
        Dim Cvar2MaxRounds As String = "mp_maxrounds " & frmMain.txtCvar2MaxRounds.Text
        Dim Cvar2WinLimit As String = "mp_winlimit" & frmMain.txtCvar2WinLimit.Text
        Dim Cvar2SpawnProtectionTime As String = "mp_spawnprotectiontime " & frmMain.txtCvar2SpawnProtectionTime.Text
        Dim Cvar2PlayerId As String = "mp_playerid " & frmMain.cbCvar2PlayerId.SelectedIndex

        'Server Logs
        Dim SlLog As String = "sv_logfile " & frmMain.cbSlLog.SelectedIndex
        Dim SlLogBans As String = "sv_logbans " & frmMain.cbSlLogBans.SelectedIndex
        Dim SlLogEcho As String = "sv_logecho " & frmMain.cbSlLogEcho.SelectedIndex
        Dim SlLogOne As String = "sv_log_onefile " & frmMain.cbSlLogOne.SelectedIndex

        'RCON
        Dim RconBanPenalty As String = "sv_rcon_banpenalty " & arrayRcon(0, frmMain.cbRconBanpenalty.SelectedIndex)
        Dim RconMaxFail As String = "sv_rcon_maxfailures " & arrayRcon(1, frmMain.cbRconMaxFail.SelectedIndex)
        Dim RconMinFail As String = "sv_rcon_minfailures " & arrayRcon(2, frmMain.cbRconMinFail.SelectedIndex)
        Dim RconMinFailTime As String = "sv_rcon_minfailuretime " & arrayRcon(3, frmMain.cbRconMinFailTime.SelectedIndex)

        'Bandwidth Rates
        Dim BrMaxRate As String = "sv_maxrate " & frmMain.txtBrMaxRate.Text
        Dim BrMinRate As String = "sv_minrate " & frmMain.txtBrMinRate.Text
        Dim BrDecalFreq As String = "decalfrequency " & frmMain.txtBrDecalFreq.Text
        Dim BrMaxUpdateRate As String = "sv_maxupdaterate " & frmMain.txtBrMaxUpdateRate.Text
        Dim BrMinUpdateRate As String = "sv_minupdaterate " & frmMain.txtBrMinUpdateRate.Text

        'Bots
        Dim BotAdd As String = "bot_add" 'Doesn't use a value, the line itself means it's on.
        Dim BotQuota As String = "bot_quota " & frmMain.cbBotQuota.SelectedIndex
        Dim BotQuotaMode As String = "bot_quota_mode " & frmMain.cbBotQuotaMode.SelectedValue
        Dim BotDifficulty As String = "bot_difficulty " & frmMain.cbBotDifficulty.SelectedIndex
        Dim BotChatter As String = "bot_chatter " & frmMain.cbBotChatter.SelectedValue
        Dim BotAutoFollow As String = "bot_auto_follow " & frmMain.cbBotAutoFollow.SelectedIndex
        Dim BotAutoVacate As String = "bot_auto_vacate " & frmMain.cbBotAutoVacate.SelectedIndex
        Dim BotJoinAfterPlayer As String = "bot_join_after_player " & frmMain.cbBotJoinAfterPlayer.SelectedIndex
        Dim BotDeferHuman As String = "bot_defer_to_human " & frmMain.cbBotDeferHuman.SelectedIndex
        Dim BotPrefix As String = "bot_prefix " & """" & frmMain.txtBotPrefix.Text & """"
        Dim BotAllowRogue As String = "bot_allow_rogues " & frmMain.cbBotAllowRogue.SelectedIndex
        Dim BotWalk As String = "bot_walk " & frmMain.cbBotWalk.SelectedIndex
        Dim BotJoinTeam As String = "bot_join_team " & frmMain.cbBotJoinTeam.SelectedValue
        Dim BotEcoLimit As String = "bot_eco_limit " & frmMain.txtBotEcoLimit.Text

        'Bot Weapons
        Dim BotGrenades As String = "bot_allow_grenades " & frmMain.cbBotGrenades.SelectedIndex
        Dim BotPistols As String = "bot_allow_pistols " & frmMain.cbBotPistols.SelectedIndex
        Dim BotSmg As String = "bot_allow_sub_machine_guns " & frmMain.cbBotSmg.SelectedIndex
        Dim BotShotguns As String = "bot_allow_shotguns " & frmMain.cbBotShotguns.SelectedIndex
        Dim BotRifles As String = "bot_allow_rifles " & frmMain.cbBotRifles.SelectedIndex
        Dim BotSnipers As String = "bot_allow_snipers " & frmMain.cbBotSnipers.SelectedIndex
        Dim BotMachineguns As String = "bot_allow_machine_guns " & frmMain.cbBotMachineguns.SelectedIndex
        'That's that, let's go on...

        'These variables are used to check if things are filled in or enabled.
        'If not, some code in the CFG can be left out, it will set to default automatically.
        Dim EnabledBots As Boolean
        Dim EnabledPass As Boolean
        Dim EnabledLog As Boolean
        Dim EnabledRcon As Boolean
        Dim FinalCase As Integer = 0 'This is used in the following cases. Short: 0=Non, 1=Bots, 2=Pass, 4=Log, 8= RCON. Done binary so just add them up and you got your outcome :)

        Select Case frmMain.cbBotAdd.SelectedIndex
            Case 1
                EnabledBots = True
                FinalCase += 1
            Case Else
                EnabledBots = False
        End Select

        Select Case frmMain.txtGeneralPassServer.Text
            Case ""
                EnabledPass = False
            Case Else
                EnabledPass = True
                FinalCase += 2
        End Select

        Select Case frmMain.cbSlLog.SelectedIndex
            Case 1
                EnabledLog = True
                FinalCase += 4
            Case Else
                EnabledLog = False
        End Select

        Select Case frmMain.txtGeneralPassRcon.Text
            Case ""
                EnabledRcon = False
            Case Else
                EnabledRcon = True
                FinalCase += 8
        End Select

        'Alright, case is set. Let's give them something to work with, shall we? :)
        'First 6 are the ones we ALWAYS use.
        Dim ServerName As String
        Dim ServerOperation As String
        Dim CvarServer As String
        Dim CvarRound As String
        Dim Bandwidth As String
        Dim BanFiles As String 'Yeah, those also exist. They're always listed though (as far as I know..)

        'Last 5 are the ones that can be disabled, depending on the cases shown above.
        Dim Bots As String
        Dim PassRcon As String
        Dim Rcon As String
        Dim Logs As String
        Dim PassServer As String


        ServerName = "//Server Name" & vbCrLf & _
        GeneralServerName

        PassRcon = vbCrLf & "//RCON Password" & vbCrLf & _
        GeneralPassRcon

        PassServer = vbCrLf & "//Server Password" & vbCrLf & _
        GeneralPassServer

        Select Case frmMain.txtGeneralContact.Text 'If no Contact Email is entered, it won't list that part.
            Case ""
                ServerOperation = vbCrLf & "//Server Operation" & vbCrLf & _
                GeneralLan & vbCrLf & _
                GeneralRegion
            Case Else
                ServerOperation = vbCrLf & "//Server Operation" & vbCrLf & _
                GeneralLan & vbCrLf & _
                GeneralRegion & vbCrLf & _
                GeneralContact
        End Select


        CvarServer = vbCrLf & "//Server Cvars" & vbCrLf & _
        CvarFriendlyFire & vbCrLf & _
        CvarFootsteps & vbCrLf & _
        CvarAutoTeamBal & vbCrLf & _
        CvarAutokick & vbCrLf & _
        CvarFlashlight & vbCrLf & _
        CvarTkPunish & vbCrLf & _
        CvarForceCam & vbCrLf & _
        CvarAllTalk & vbCrLf & _
        CvarPausable & vbCrLf & _
        CvarConsistency & vbCrLf & _
        CvarCheats & vbCrLf & _
        CvarAllowUpload & vbCrLf & _
        CvarAllowDownload & vbCrLf & _
        CvarMaxSpeed & vbCrLf & _
        CvarLimitTeams & vbCrLf & _
        CvarHostagePenalty & vbCrLf & _
        CvarVoiceEnable & vbCrLf & _
        CvarAllowSpectate & vbCrLf & _
        CvarTimeLimit & vbCrLf & _
        CvarChatTime & vbCrLf & _
        CvarTimeout

        CvarRound = vbCrLf & "//Round Cvars" & vbCrLf & _
        Cvar2FreezeTime & vbCrLf & _
        Cvar2RoundTime & vbCrLf & _
        Cvar2StartMoney & vbCrLf & _
        Cvar2BombTimer & vbCrLf & _
        Cvar2FragLimit & vbCrLf & _
        Cvar2MaxRounds & vbCrLf & _
        Cvar2WinLimit & vbCrLf & _
        Cvar2SpawnProtectionTime & vbCrLf & _
        Cvar2PlayerId

        Logs = vbCrLf & "//Server Logs" & vbCrLf & _
        SlLog & vbCrLf & _
        SlLogBans & vbCrLf & _
        SlLogEcho & vbCrLf & _
        SlLogOne

        If frmMain.cbRconBanpenalty.SelectedIndex = 0 Then
            Rcon = vbCrLf & "//RCON Security" & vbCrLf & _
            "//RCON BanPenalty is disabled."
        Else
            Rcon = vbCrLf & "//RCON Security" & vbCrLf & _
            RconBanPenalty & vbCrLf & _
            RconMaxFail & vbCrLf & _
            RconMinFail & vbCrLf & _
            RconMinFailTime
        End If

        Bandwidth = vbCrLf & "//Bandwidth Settings" & vbCrLf & _
        BrMaxRate & vbCrLf & _
        BrMinRate & vbCrLf & _
        BrDecalFreq & vbCrLf & _
        BrMaxUpdateRate & vbCrLf & _
        BrMinUpdateRate

        Bots = vbCrLf & "//Bot Set-up" & vbCrLf & _
        BotAdd & vbCrLf & _
        BotQuota & vbCrLf & _
        BotQuotaMode & vbCrLf & _
        BotDifficulty & vbCrLf & _
        BotChatter & vbCrLf & _
        BotAutoFollow & vbCrLf & _
        BotAutoVacate & vbCrLf & _
        BotJoinAfterPlayer & vbCrLf & _
        BotDeferHuman & vbCrLf & _
        BotPrefix & vbCrLf & _
        BotAllowRogue & vbCrLf & _
        BotWalk & vbCrLf & _
        BotJoinTeam & vbCrLf & _
        BotEcoLimit & vbCrLf & _
        BotGrenades & vbCrLf & _
        BotPistols & vbCrLf & _
        BotSmg & vbCrLf & _
        BotShotguns & vbCrLf & _
        BotRifles & vbCrLf & _
        BotSnipers & vbCrLf & _
        BotMachineguns

        BanFiles = vbCrLf & "//Ban Files" & vbCrLf & _
        "exec banned_user.cfg" & vbCrLf & _
        "execbanned_ip.cfg"

        'The last bit, the code will build here. Writing this in binary sucks :<
        Select Case FinalCase
            Case 0 '0000
                funcCodeBuild = ServerName & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 1 '0001
                funcCodeBuild = ServerName & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Bots & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 2 '0010
                funcCodeBuild = ServerName & vbCrLf & PassServer & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 3 '0011
                funcCodeBuild = ServerName & vbCrLf & PassServer & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Bots & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 4 '0100
                funcCodeBuild = ServerName & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Logs & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 5 '0101
                funcCodeBuild = ServerName & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Logs & vbCrLf & Bots & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 6 '0110
                funcCodeBuild = ServerName & vbCrLf & PassServer & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Logs & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 7 '0111
                funcCodeBuild = ServerName & vbCrLf & PassServer & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Logs & vbCrLf & Bots & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 8 '1000
                funcCodeBuild = ServerName & vbCrLf & PassRcon & vbCrLf & Rcon & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 9 '1001
                funcCodeBuild = ServerName & vbCrLf & PassRcon & vbCrLf & Rcon & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Bots & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 10 '1010
                funcCodeBuild = ServerName & vbCrLf & PassServer & vbCrLf & PassRcon & vbCrLf & Rcon & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 11 '1011
                funcCodeBuild = ServerName & vbCrLf & PassServer & vbCrLf & PassRcon & vbCrLf & Rcon & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Bots & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 12 '1100
                funcCodeBuild = ServerName & vbCrLf & PassRcon & vbCrLf & Rcon & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Logs & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 13 '1101
                funcCodeBuild = ServerName & vbCrLf & PassRcon & vbCrLf & Rcon & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Logs & vbCrLf & Bots & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 14 '1110
                funcCodeBuild = ServerName & vbCrLf & PassServer & vbCrLf & PassRcon & vbCrLf & Rcon & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Logs & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case 15 '1111
                funcCodeBuild = ServerName & vbCrLf & PassServer & vbCrLf & PassRcon & vbCrLf & Rcon & vbCrLf & CvarServer & vbCrLf & CvarRound & vbCrLf & Bandwidth & vbCrLf & Logs & vbCrLf & Bots & vbCrLf & ServerOperation & vbCrLf & BanFiles
            Case Else
                funcCodeBuild = "Something in the code generation went wrong..."
        End Select
        'Let's see if this works :>

    End Function

#Region "Settings Save/Load/Reset functions"
    ''' <summary>
    ''' Saves the current settings into My.Settings. Overwrites the previous settings.
    ''' </summary>
    Function funcSettingsSave() As Boolean
        'General
        My.Settings.generalLan = frmMain.cbGeneralLan.SelectedIndex
        My.Settings.generalLocation = frmMain.cbGeneralRegion.SelectedIndex

        'Server Cvars
        My.Settings.cvarFriendlyFire = frmMain.cbCvarFriendlyFire.SelectedIndex
        My.Settings.cvarFootsteps = frmMain.cbCvarFootsteps.SelectedIndex
        My.Settings.cvarAutoTeamBal = frmMain.cbCvarAutoTeamBal.SelectedIndex
        My.Settings.cvarAutoKick = frmMain.cbCvarAutokick.SelectedIndex
        My.Settings.cvarFlashlight = frmMain.cbCvarFlashlight.SelectedIndex
        My.Settings.cvarTkPunish = frmMain.cbCvarTkPunish.SelectedIndex
        My.Settings.cvarForceCam = frmMain.cbCvarForceCam.SelectedIndex
        My.Settings.cvarAllTalk = frmMain.cbCvarAllTalk.SelectedIndex
        My.Settings.cvarPausable = frmMain.cbCvarPausable.SelectedIndex
        My.Settings.cvarConsistency = frmMain.cbCvarConsistency.SelectedIndex
        My.Settings.cvarCheats = frmMain.cbCvarCheats.SelectedIndex
        My.Settings.cvarAllowUpload = frmMain.cbCvarAllowUpload.SelectedIndex
        My.Settings.cvarAllowDownload = frmMain.cbCvarAllowDownload.SelectedIndex
        My.Settings.cvarMaxSpeed = frmMain.txtCvarMaxSpeed.Text
        My.Settings.cvarLimitTeams = frmMain.txtCvarLimitTeams.Text
        My.Settings.cvarHostagePenalty = frmMain.txtCvarHostagePenalty.Text
        My.Settings.cvarVoiceEnable = frmMain.cbCvarVoiceEnable.SelectedIndex
        My.Settings.cvarAllowSpectate = frmMain.cbCvarAllowSpectate.SelectedIndex
        My.Settings.cvarTimeLimit = frmMain.txtCvarTimeLimit.Text
        My.Settings.cvarChatTime = frmMain.txtCvarChatTime.Text
        My.Settings.cvarTimeout = frmMain.cbCvarTimeout.SelectedIndex

        'Round Cvars
        My.Settings.cvar2FreezeTime = frmMain.txtCvar2FreezeTime.Text
        My.Settings.cvar2RoundTime = frmMain.txtCvar2RoundTime.Text
        My.Settings.cvar2StartMoney = frmMain.txtCvar2StartMoney.Text
        My.Settings.cvar2BombTimer = frmMain.txtCvar2BombTimer.Text
        My.Settings.cvar2FragLimit = frmMain.txtCvar2FragLimit.Text
        My.Settings.cvar2MaxRounds = frmMain.txtCvar2MaxRounds.Text
        My.Settings.cvar2WinLimit = frmMain.txtCvar2WinLimit.Text
        My.Settings.cvar2SpawnProtectionTime = frmMain.txtCvar2SpawnProtectionTime.Text
        My.Settings.cvar2PlayerId = frmMain.cbCvar2PlayerId.SelectedIndex

        'Server Logs
        My.Settings.slLog = frmMain.cbSlLog.SelectedIndex
        My.Settings.slLogBans = frmMain.cbSlLogBans.SelectedIndex
        My.Settings.slLogEcho = frmMain.cbSlLogEcho.SelectedIndex
        My.Settings.slLogOne = frmMain.cbSlLogOne.SelectedIndex

        'RCON
        My.Settings.rconBanPenalty = frmMain.cbRconBanpenalty.SelectedIndex
        My.Settings.rconMaxFailures = frmMain.cbRconMaxFail.SelectedIndex
        My.Settings.rconMinFailures = frmMain.cbRconMinFail.SelectedIndex
        My.Settings.rconMinFailureTime = frmMain.cbRconMinFailTime.SelectedIndex

        'Bandwidth Rates
        My.Settings.brMinRate = frmMain.txtBrMinRate.Text
        My.Settings.brMaxRate = frmMain.txtBrMaxRate.Text
        My.Settings.brDecalFreq = frmMain.txtBrDecalFreq.Text
        My.Settings.brMaxUpdateRate = frmMain.txtBrMaxUpdateRate.Text
        My.Settings.brMinUpdateRate = frmMain.txtBrMinUpdateRate.Text

        'Bots
        My.Settings.botAdd = frmMain.cbBotAdd.SelectedIndex
        My.Settings.botQuota = frmMain.cbBotQuota.SelectedIndex
        My.Settings.botQuotaMode = frmMain.cbBotQuotaMode.SelectedIndex
        My.Settings.botDifficulty = frmMain.cbBotDifficulty.SelectedIndex
        My.Settings.botChatter = frmMain.cbBotChatter.SelectedIndex
        My.Settings.botAutoFollow = frmMain.cbBotAutoFollow.SelectedIndex
        My.Settings.botAutoVacate = frmMain.cbBotAutoVacate.SelectedIndex
        My.Settings.botJoinAfterPlayer = frmMain.cbBotJoinAfterPlayer.SelectedIndex
        My.Settings.botDeferHuman = frmMain.cbBotDeferHuman.SelectedIndex
        My.Settings.botPrefix = frmMain.txtBotPrefix.Text
        My.Settings.botAllowRogue = frmMain.cbBotAllowRogue.SelectedIndex
        My.Settings.botWalk = frmMain.cbBotWalk.SelectedIndex
        My.Settings.botJoinTeam = frmMain.cbBotJoinTeam.SelectedIndex
        My.Settings.botEcoLimit = frmMain.txtBotEcoLimit.Text

        'Bot Weapons
        My.Settings.botGrenades = frmMain.cbBotGrenades.SelectedIndex
        My.Settings.botPistols = frmMain.cbBotPistols.SelectedIndex
        My.Settings.botSMGs = frmMain.cbBotSmg.SelectedIndex
        My.Settings.botShotguns = frmMain.cbBotShotguns.SelectedIndex
        My.Settings.botRifles = frmMain.cbBotRifles.SelectedIndex
        My.Settings.botSnipers = frmMain.cbBotSnipers.SelectedIndex
        My.Settings.botMachineguns = frmMain.cbBotMachineguns.SelectedIndex
    End Function

    ''' <summary>
    ''' Saves the current settings into My.Settings. Overwrites the previous settings.
    ''' </summary>
    Function funcSettingsReset() As Boolean
        'This resets the basic settings after you changed them with the Save Default option.
        'General
        My.Settings.generalLan = 0
        My.Settings.generalLocation = 8

        'Server Cvars
        My.Settings.cvarFriendlyFire = 0
        My.Settings.cvarFootsteps = 1
        My.Settings.cvarAutoTeamBal = 1
        My.Settings.cvarAutoKick = 0
        My.Settings.cvarFlashlight = 0
        My.Settings.cvarTkPunish = 1
        My.Settings.cvarForceCam = 0
        My.Settings.cvarAllTalk = 0
        My.Settings.cvarPausable = 0
        My.Settings.cvarConsistency = 1
        My.Settings.cvarCheats = 0
        My.Settings.cvarAllowUpload = 1
        My.Settings.cvarAllowDownload = 1
        My.Settings.cvarMaxSpeed = "320"
        My.Settings.cvarLimitTeams = "2"
        My.Settings.cvarHostagePenalty = "5"
        My.Settings.cvarVoiceEnable = 1
        My.Settings.cvarAllowSpectate = 1
        My.Settings.cvarTimeLimit = "25"
        My.Settings.cvarChatTime = "10"
        My.Settings.cvarTimeout = 5

        'Round Cvars
        My.Settings.cvar2FreezeTime = "6"
        My.Settings.cvar2RoundTime = "5"
        My.Settings.cvar2StartMoney = "800"
        My.Settings.cvar2BombTimer = "45"
        My.Settings.cvar2FragLimit = "0"
        My.Settings.cvar2MaxRounds = "0"
        My.Settings.cvar2WinLimit = "0"
        My.Settings.cvar2SpawnProtectionTime = "5"
        My.Settings.cvar2PlayerId = 0

        'Server Logs
        My.Settings.slLog = 0
        My.Settings.slLogBans = 0
        My.Settings.slLogEcho = 1
        My.Settings.slLogOne = 0

        'RCON
        My.Settings.rconBanPenalty = 0
        My.Settings.rconMaxFailures = 9
        My.Settings.rconMinFailures = 4
        My.Settings.rconMinFailureTime = 5

        'Bandwidth Rates
        My.Settings.brMinRate = "0"
        My.Settings.brMaxRate = "0"
        My.Settings.brDecalFreq = "10"
        My.Settings.brMaxUpdateRate = "60"
        My.Settings.brMinUpdateRate = "10"

        'Bots
        My.Settings.botAdd = 0
        My.Settings.botQuota = 4
        My.Settings.botQuotaMode = 0
        My.Settings.botDifficulty = 1
        My.Settings.botChatter = 3
        My.Settings.botAutoFollow = 1
        My.Settings.botAutoVacate = 1
        My.Settings.botJoinAfterPlayer = 1
        My.Settings.botDeferHuman = 0
        My.Settings.botPrefix = ""
        My.Settings.botAllowRogue = 0
        My.Settings.botWalk = 1
        My.Settings.botJoinTeam = 0
        My.Settings.botEcoLimit = "2000"

        'Bot Weapons
        My.Settings.botGrenades = 1
        My.Settings.botPistols = 1
        My.Settings.botSMGs = 1
        My.Settings.botShotguns = 1
        My.Settings.botRifles = 1
        My.Settings.botSnipers = 1
        My.Settings.botMachineguns = 1
        'End of the reset code.
    End Function

    ''' <summary>
    ''' Opens the current settings from My.Settings.
    ''' </summary>
    Function funcSettingsOpen() As Boolean
        'This is where the basic settings are loaded. They are saved in the Settings section of "My Project".
        'Let's see how good this works, should save time hard-coding it in :)
        'NOTE: "Default" settings are in the Load Event code (below), these have
        '_NOTHING_ to do with these values. That is just for the reset functionality of the tool.
        '
        'As you can see, this is an exact copy of the load event. This is because I'm too lazy to write a function or something for it.

        'General
        frmMain.cbGeneralLan.SelectedIndex = My.Settings.generalLan
        frmMain.cbGeneralRegion.SelectedIndex = My.Settings.generalLocation

        'Server Cvars
        frmMain.cbCvarFriendlyFire.SelectedIndex = My.Settings.cvarFriendlyFire
        frmMain.cbCvarFootsteps.SelectedIndex = My.Settings.cvarFootsteps
        frmMain.cbCvarAutoTeamBal.SelectedIndex = My.Settings.cvarAutoTeamBal
        frmMain.cbCvarAutokick.SelectedIndex = My.Settings.cvarAutoKick
        frmMain.cbCvarFlashlight.SelectedIndex = My.Settings.cvarFlashlight
        frmMain.cbCvarTkPunish.SelectedIndex = My.Settings.cvarTkPunish
        frmMain.cbCvarForceCam.SelectedIndex = My.Settings.cvarForceCam
        frmMain.cbCvarAllTalk.SelectedIndex = My.Settings.cvarAllTalk
        frmMain.cbCvarPausable.SelectedIndex = My.Settings.cvarPausable
        frmMain.cbCvarConsistency.SelectedIndex = My.Settings.cvarConsistency
        frmMain.cbCvarCheats.SelectedIndex = My.Settings.cvarCheats
        frmMain.cbCvarAllowUpload.SelectedIndex = My.Settings.cvarAllowUpload
        frmMain.cbCvarAllowDownload.SelectedIndex = My.Settings.cvarAllowDownload
        frmMain.txtCvarMaxSpeed.Text = My.Settings.cvarMaxSpeed
        frmMain.txtCvarLimitTeams.Text = My.Settings.cvarLimitTeams
        frmMain.txtCvarHostagePenalty.Text = My.Settings.cvarHostagePenalty
        frmMain.cbCvarVoiceEnable.SelectedIndex = My.Settings.cvarVoiceEnable
        frmMain.cbCvarAllowSpectate.SelectedIndex = My.Settings.cvarAllowSpectate
        frmMain.txtCvarTimeLimit.Text = My.Settings.cvarTimeLimit
        frmMain.txtCvarChatTime.Text = My.Settings.cvarChatTime
        frmMain.cbCvarTimeout.SelectedIndex = My.Settings.cvarTimeout

        'Round Cvars
        frmMain.txtCvar2FreezeTime.Text = My.Settings.cvar2FreezeTime
        frmMain.txtCvar2RoundTime.Text = My.Settings.cvar2RoundTime
        frmMain.txtCvar2StartMoney.Text = My.Settings.cvar2StartMoney
        frmMain.txtCvar2BombTimer.Text = My.Settings.cvar2BombTimer
        frmMain.txtCvar2FragLimit.Text = My.Settings.cvar2FragLimit
        frmMain.txtCvar2MaxRounds.Text = My.Settings.cvar2MaxRounds
        frmMain.txtCvar2WinLimit.Text = My.Settings.cvar2WinLimit
        frmMain.txtCvar2SpawnProtectionTime.Text = My.Settings.cvar2SpawnProtectionTime
        frmMain.cbCvar2PlayerId.SelectedIndex = My.Settings.cvar2PlayerId

        'Server Logs
        frmMain.cbSlLog.SelectedIndex = My.Settings.slLog
        frmMain.cbSlLogBans.SelectedIndex = My.Settings.slLogBans
        frmMain.cbSlLogEcho.SelectedIndex = My.Settings.slLogEcho
        frmMain.cbSlLogOne.SelectedIndex = My.Settings.slLogOne

        'RCON
        frmMain.cbRconBanpenalty.SelectedIndex = My.Settings.rconBanPenalty
        frmMain.cbRconMaxFail.SelectedIndex = My.Settings.rconMaxFailures
        frmMain.cbRconMinFail.SelectedIndex = My.Settings.rconMinFailures
        frmMain.cbRconMinFailTime.SelectedIndex = My.Settings.rconMinFailureTime

        'Bandwidth Rates
        frmMain.txtBrMaxRate.Text = My.Settings.brMaxRate
        frmMain.txtBrMinRate.Text = My.Settings.brMinRate
        frmMain.txtBrDecalFreq.Text = My.Settings.brDecalFreq
        frmMain.txtBrMaxUpdateRate.Text = My.Settings.brMaxUpdateRate
        frmMain.txtBrMinUpdateRate.Text = My.Settings.brMinUpdateRate

        'Bots
        frmMain.cbBotAdd.SelectedIndex = My.Settings.botAdd
        frmMain.cbBotQuota.SelectedIndex = My.Settings.botQuota
        frmMain.cbBotQuotaMode.SelectedIndex = My.Settings.botQuotaMode
        frmMain.cbBotDifficulty.SelectedIndex = My.Settings.botDifficulty
        frmMain.cbBotChatter.SelectedIndex = My.Settings.botChatter
        frmMain.cbBotAutoFollow.SelectedIndex = My.Settings.botAutoFollow
        frmMain.cbBotAutoVacate.SelectedIndex = My.Settings.botAutoVacate
        frmMain.cbBotJoinAfterPlayer.SelectedIndex = My.Settings.botJoinAfterPlayer
        frmMain.cbBotDeferHuman.SelectedIndex = My.Settings.botDeferHuman
        frmMain.txtBotPrefix.Text = My.Settings.botPrefix
        frmMain.cbBotAllowRogue.SelectedIndex = My.Settings.botAllowRogue
        frmMain.cbBotWalk.SelectedIndex = My.Settings.botWalk
        frmMain.cbBotJoinTeam.SelectedIndex = My.Settings.botJoinTeam
        frmMain.txtBotEcoLimit.Text = My.Settings.botEcoLimit

        'Bot Weapons
        frmMain.cbBotGrenades.SelectedIndex = My.Settings.botGrenades
        frmMain.cbBotPistols.SelectedIndex = My.Settings.botPistols
        frmMain.cbBotSmg.SelectedIndex = My.Settings.botSMGs
        frmMain.cbBotShotguns.SelectedIndex = My.Settings.botShotguns
        frmMain.cbBotRifles.SelectedIndex = My.Settings.botRifles
        frmMain.cbBotSnipers.SelectedIndex = My.Settings.botSnipers
        frmMain.cbBotMachineguns.SelectedIndex = My.Settings.botMachineguns
        'End of grabbing the settings.
    End Function
#End Region
End Module
